﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/25/2009
 * Time: 3:25 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Miming.Model;

namespace Miming.Gui
{
	/// <summary>
	/// Description of EmployeeListForm.
	/// </summary>
	public partial class EmployeeListForm : BaseForm
	{
		public EmployeeListForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			listView1.Resize += delegate { columnHeader1.Width = listView1.Width - 22; };
			newToolStripMenuItem.Click += delegate { MainForm.Instance.AddChild(new EmployeeForm()); };
		}
		
		[System.ComponentModel.EditorBrowsableAttribute()]
		protected override void OnActivated(EventArgs e)
		{
			base.OnActivated(e);
			Model = SessionFacade.FindAllEmployees();
		}
		
		protected override void OnModelChanged(EventArgs ev)
		{
			base.OnModelChanged(ev);
			listView1.Items.Clear();
			foreach (Employee e in Model as IList<Employee>) {
				ListViewItem li = listView1.Items.Add(e.Name.ToString());
			}
		}
		
		void ListView1DoubleClick(object sender, EventArgs ev)
		{
			if (listView1.SelectedItems.Count > 0) {
				Employee e = (Model as IList<Employee>)[listView1.SelectedItems[0].Index];
				MainForm.Instance.AddChild(new EmployeeForm(e), "Edit Employee");
			}
		}
	}
}
